package Eclass.Batch;

import ibatis.IbatisHelper;

import java.util.*;
import java.sql.*;

import com.ibatis.sqlmap.client.SqlMapClient;

public class BatchManager {
	private SqlMapClient ibatis;

	public BatchManager() {
		this.ibatis = IbatisHelper.getSqlMapInstance();
	}
	
	public List selectAll(){
		List result = null;
		
		try {
			result = ibatis.queryForList("batch.getBatch","");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public boolean addBatch(BatchModel bean) {
		try {
			ibatis.startTransaction();
			this.ibatis.insert("batch.insert", bean);
			ibatis.commitTransaction();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		} finally {
			try {
				ibatis.endTransaction();
			} catch (Exception e2) {
				// TODO: handle exception
				e2.printStackTrace();
				//return false;
			}
		}
		return true;
	}
	
	public BatchModel selectBatch(String id) {
		BatchModel result = new BatchModel();
		try {
			result = (BatchModel) ibatis.queryForObject("batch.getSelectedBatch", id);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} 
		return result;
	}
	
	public boolean updateBatch(BatchModel bean) {
		try {
			ibatis.startTransaction();
			this.ibatis.update("batch.update", bean);
			ibatis.commitTransaction();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		} finally {
			try {
				ibatis.endTransaction();
			} catch (Exception e2) {
				// TODO: handle exception
				e2.printStackTrace();
				//return false;
			}
		}
		return true;
	}
}
